<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>iBizSys vscode 登录重定向</title>
    <link rel="icon" href="./favicon.ico" />
    <link rel="stylesheet" type="text/css" href="./common.css" />
    <link rel="stylesheet" type="text/css" href="./index.css" />
    <script src="../../environments/environment.js"></script>
  </head>
  <body>
    <div class="page flex-col">
      <div class="wrap1 flex-col">
        <div class="mod1 flex-col">
          <div class="group1 flex-col"></div>
          <span class="word1">
            授权Visual&nbsp;Studio&nbsp;Code访问&nbsp;iBiz&nbsp;Modeling
          </span>
          <span class="txt1">
            如果您代码已启动了授权，请单击“继续”以授权对&nbsp;iBiz&nbsp;Modeling&nbsp;的访问
          </span>
          <button id="login-action" class="group2 flex-col">
            <span class="word2">继续</span>
          </button>
          <a href="https://www.ibizlab.cn" class="info1">
            不授权
          </a>
        </div>
      </div>
      <span class="word11">
        将&nbsp;Visual&nbsp;Studio&nbsp;Code&nbsp;连接到&nbsp;iBiz&nbsp;Modeling&nbsp;需要此服务，并且不存储任何敏感信息.
      </span>
    </div>
    <script>
      function getQueryVariable(variable) {
        var query = location.search.substring(1);
        var vars = query.split('&');
        for (var i = 0; i < vars.length; i++) {
          var pair = vars[i].split('=');
          if (pair[0] == variable) {
            return pair[1];
          }
        }
        return false;
      }
      function redirect() {
        const cas = window.Environment.casUrl;
        let service = getQueryVariable('service');
        service = decodeURIComponent(decodeURIComponent(service));
        let path = location.pathname
          .replace('/vscode-auth/redirect/index.html', '')
          .replace('/vscode-auth/redirect/', '');
        const url = `${location.origin}${path}/vscode-auth/index.html?RU=${encodeURIComponent(service)}`;
        const href = `${cas}/login?service=${encodeURIComponent(url)}`;
        window.location.href = href;
      }
      window.onload = function() {
        const btn = document.getElementById('login-action');
        btn.onclick = function() {
          redirect();
        };
      };
    </script>
  </body>
</html>
